﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using HZ.MBSM.DBUtility;

public partial class Manage_bidTableUpdate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        System.Collections.Generic.List<HZ.MBSM.DAL.AccountType> _AccountType = new System.Collections.Generic.List<HZ.MBSM.DAL.AccountType>();
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumAttorney );
        _AccountType.Add(HZ.MBSM.DAL.AccountType.enumCheckProjectComp);

        if (HZ.MBSM.BLL.Login.CheckAssert(_AccountType))
        {

            if (!IsPostBack)
            {
                string BidTableId, strSql;
                
                BidTableId = SysFun.IsSQL(SysFun.ToTrim(Request.QueryString["BidTableId"]));
                if (BidTableId == "")
                {
                    Response.Write("<script language=JavaScript>window.alert('没有找到相关的品种！！！！');();</script>");
                    Response.Write("<script language=JavaScript>window.close();</script>");
                }
                else
                {
                    Db db = new Db();
                    System.Data.IDataReader dr;
                    strSql = "select * from BidTable where  BidTableId=" + BidTableId;
                    dr = db.DataReader(strSql);
                    while (dr.Read())
                    {
                        txtBidTableName.Text = SysFun.ToTrim(dr["BidTableName"]);
                        txtBidTableId.Text = SysFun.ToTrim(dr["BidTableId"]);
                        txtBidTableId.Visible = false;
                        txtBidTableOutlookc.Text = SysFun.ToTrim(dr["BidTableOutlookc"]);
                        txtBidTableType.Text = SysFun.ToTrim(dr["BidTableType"]);
                        txtProductCode.Text = SysFun.ToTrim(dr["ProductCode"]);
                        
                        txtZL1.Text = SysFun.ToTrim(dr["ZL1"]);
                        txtHL1.Text = SysFun.ToTrim(dr["HL1"]);
                    }
                    dr.Dispose();
                    dr.Close();
                    db.Close();

                }
            }
        }
    }
    protected void butSave_Click(object sender, EventArgs e)
    {
        Int64 BidTableId;
        int  FieldCount = 0;
        string strSql, BidTableName, BidTableOutlookc, BidTableType, ProductCode;
        double ZL1 = 0, HL1 = 0;
        BidTableId = SysFun.ToLong(txtBidTableId.Text);
        
        BidTableName = SysFun.ToTrim(txtBidTableName.Text);
        BidTableOutlookc = SysFun.ToTrim(txtBidTableOutlookc.Text);
        BidTableType = SysFun.ToTrim(txtBidTableType.Text);
        ProductCode = SysFun.ToTrim(txtProductCode.Text);
        
        if (txtZL1.Text != "")
            ZL1 = Convert.ToDouble(txtZL1.Text);
        if (txtHL1.Text != "")
            HL1 = Convert.ToDouble(txtHL1.Text);

        Db db = new Db();
        System.Data.IDataReader dr;
        strSql = "select count(*) as cun from  bidTable where BidTableId<>" + BidTableId + "  and ((BidTableName='" + BidTableName + "' and BidTableOutlookc='" + BidTableOutlookc + "' and BidTableType='" + BidTableType + "') or ProductCode='" + ProductCode + "')";
        dr = db.DataReader(strSql);
        if (dr.Read())
        {
            FieldCount = SysFun.ToInt(dr["cun"]);
        }
        dr.Close();
        dr.Dispose();
        if (FieldCount == 0)
        {
            Grove.ORM.ObjectOperator oo = db.GetObjectOperator();
            HZ.MBSM.Model.bidTable bidTable = new HZ.MBSM.Model.bidTable();
            bidTable.BidTableId = BidTableId;
            bidTable.BidTableName = BidTableName;
            bidTable.BidTableOutlookc = BidTableOutlookc;
            bidTable.BidTableType = BidTableType;
            bidTable.ProductCode = ProductCode;
            bidTable.ProjectId = 1;
            if (ZL1 > 0)
                bidTable.ZL1 = ZL1;
            if (HL1 > 0)
                bidTable.HL1 = HL1;
            oo.Update(bidTable);
            oo.Dispose();
            HZ.MBSM.Model.Account _Account = (HZ.MBSM.Model.Account)Session["Account"];
            HZ.MBSM.BLL.LogManage.RecordLoginDetail(_Account.AccountName, Request.UserHostAddress, "更新", "bid_project_product", "oo.Update(bidTable)" + bidTable.BidTableId.ToString(), "../Agency/bidTableUpdate.aspx");

            Response.Write("<script>window.opener.location.reload();window.close();</script>");
        }
        else
        {
            Response.Write("<script language=JavaScript>window.alert('该记录在数据库中已经存在！！！！');</script>");
        }

    }
    protected void butClose_Click(object sender, EventArgs e)
    {
        Response.Write("<script>window.opener.location.reload();window.close();</script>");
    }
}
